package panel.recommendPathList
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import inerface.ISysRecommendPathListPanel;
	
	import main.ClientConstants;
	
	import panel.eating.DragContainerBox;
	
	public class SysRecommendPathListPanel extends Sprite implements ISysRecommendPathListPanel
	{
		private var container:DragContainerBox;
		
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var boxList:SysPathList;
		
		private var _onShowDetail:Function;
		
		private var showChoosenPathBtn:Sprite;
		
		private var showMyPath:Function;
		
		public function SysRecommendPathListPanel()
		{
		}
		
		public function set changeData(list:Array):void
		{
			boxList.changeData(list);
			
			container.changeData([boxList]);
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			initThis();
		}
		
		private function initThis():void
		{
			var img:Bitmap = new _loader.uiManager.componentBack as Bitmap;
			img.width = _stage.stageWidth;
			img.height = _stage.stageHeight * .1;
			
			var text:TextField = new TextField;
			text.wordWrap = false;
			text.multiline = false;
			text.selectable = false;
			
			showChoosenPathBtn = new Sprite;
			showChoosenPathBtn.addChild(img);
			showChoosenPathBtn.addChild(text);
			
			TextFieldUtils.setHtmlText(text,HtmlText.formatSizeColor("<b>点击查看我的路线</b>",0x000000,18));
			text.width = text.textWidth + 5;
			text.height = text.textHeight + 5;
			text.x = (img.width - text.width) / 2;
			text.y = (img.height - text.height) / 2;
			
			this.addChild(showChoosenPathBtn);
			showChoosenPathBtn.x = 0;
			showChoosenPathBtn.y = _stage.stageHeight * ClientConstants.HOME_UP_PER;
			
			showChoosenPathBtn.buttonMode = true;
			showChoosenPathBtn.addEventListener(MouseEvent.CLICK,showMyHandler);
			
			container = new DragContainerBox(_stage.stageWidth,_stage.stageHeight * .82,_stage);
			this.addChild(container);
			container.x = 0;
			container.y = _stage.stageHeight * .18;
			
			boxList = new SysPathList(_stage,_loader,_lang,_uri);
			boxList.showDetail = _onShowDetail;
			
		}
		
		protected function showMyHandler(event:MouseEvent):void
		{
			if(showMyPath is Function){
				showMyPath();
			}
		}
		
		public function set showChoosenPath(func:Function):void
		{
			showMyPath = func;
		}
		
		public function set onShowDetail(func:Function):void
		{
			_onShowDetail = func;
		}
		
		public function clear():void
		{
			if(_stage){
				_stage = null;
				_loader = null;
				_lang = null;
				_uri = null;
				
				boxList.clear();
				container.clear();
			}
		}
	}
}